﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;

namespace BusinessLogic
{
    [Serializable]
    public class Note : Table
    {
        #region Fields
        private string _text;
        private Guid _constituentID;
        private Constituent _constituent;
        #endregion        

        #region Methods
        public bool Create()
        {            
            try
            {
                this._id = NoteDataAccess.Create(this);

                if (this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }

            return false;
        }

        public void Delete()
        {
            NoteDataAccess.Delete(this._id);
        }

        public static List<Note> GetAllByConstituentID(Guid constituentID)
        {
            return NoteDataAccess.GetAllByConstituentID(constituentID);
        }

        public void Update()
        {
            NoteDataAccess.Update(this);
        }
        #endregion

        #region Properties
        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }   

        public Constituent Constituent
        {
            get { return _constituent; }
            set 
            {             
                _constituent = value; 
                _constituentID = _constituent.ID;
            }
        }

        public Guid ConstituentID
        {
            get 
            { 
                if(_constituentID == Guid.Empty && _constituent != null)
                {
                    _constituentID = _constituent.ID;
                }

                return _constituentID; 
            }
            set 
            { 
                _constituentID = value; 
                _constituent = new Constituent();
                _constituent.FillByID(_constituentID);
            }
        }
        #endregion
    }
}